package com.ctshk.app.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.ContentDTO;
import com.ctshk.rpc.cms.req.ContentAddReq;
import com.ctshk.rpc.cms.req.ContentQueryReq;
import com.ctshk.rpc.cms.req.ContentUpdateReq;
import com.ctshk.rpc.cms.req.UpdateStatusReq;
import com.ctshk.rpc.cms.service.IContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 内容管理表 前端控制器
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
@Api(value = "内容管理-app",tags = "内容管理-app")
@RestController
@RequestMapping("/content-app")
public class ContentController extends BaseController {
    @DubboReference
    private IContentService contentService;

    @ApiOperation(value = "新增内容-app", notes = "新增内容-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.ADD)
    @PostMapping("/add")
    public Result add(@RequestBody @Valid ContentAddReq req) {
        return contentService.insert(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询内容-app", notes = "查询内容-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/queryById/{contentId}")
    public Result<ContentDTO> queryById(@PathVariable("contentId") String contentId) {
        return contentService.queryById(contentId);
    }

    @ApiOperation(value = "内容分页查询-app", notes = "内容分页查询-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/queryList")
    public PageResponse<ContentDTO> queryList(@RequestBody @Valid ContentQueryReq req) {
        return contentService.queryList(req);
    }

    @ApiOperation(value = "修改内容-app", notes = "修改内容-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/update")
    public Result update(@RequestBody @Valid ContentUpdateReq req) {
        return contentService.update(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "修改有效状态-app", notes = "修改有效状态-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/updateStatusById")
    public Result updateStatusById(@RequestBody @Valid UpdateStatusReq req) {
        return contentService.updateStatusById(req);
    }

    @ApiOperation(value = "自增指定内容浏览记录-app", notes = "自增指定内容浏览记录-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @GetMapping("/updateCountById/{id}")
    public Result updateCountById(@PathVariable("id") Long id) {
        return contentService.updateCountById(id);
    }
}
